package com.helloworld.adapter;

import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by PC_WLT on 2017/6/30.
 */

public class BasePagerAdapter extends PagerAdapter { 
        private List<View> views = new ArrayList<View>();
         private View mCurrentView;

        public BasePagerAdapter(List<View> views) {
            this.views = views;
        }

        @Override
        public boolean isViewFromObject(View arg0,Object arg1){
            return arg0 == arg1;
        }

        @Override
        public int getCount(){
            return views.size ();
        }

        @Override
        public void destroyItem(View container,int position,Object object){
            ((ViewPager) container).removeView (views.get (position));
        }

        @Override
        public Object instantiateItem(View container,int position){
            ((ViewPager) container).addView (views.get (position));
            return views.get (position);
        }

    @Override
    public void setPrimaryItem(ViewGroup container, int position, Object object) {
        mCurrentView = (View)object;
    }

    public View getPrimaryItem() {
        return mCurrentView;
    }
}
